package com.huangkailong.leetcode.util;

import java.awt.*;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.io.IOException;
import java.util.Objects;

/**
 * @author huangkl
 * @since 1.0.0
 */
public class QuestionCommentUtil {
    public static void main(String[] args) throws IOException, UnsupportedFlavorException {
        Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
        Transferable contents = clipboard.getContents(null);
        if(Objects.isNull(contents)){
            System.out.println("剪贴板无内容!");
            return;
        }
        if(!contents.isDataFlavorSupported(DataFlavor.stringFlavor)){
            System.out.println("剪贴板的内容不是文本类型，不支持!");
            return;
        }
        Object strObj = contents.getTransferData(DataFlavor.stringFlavor);
        String str = (String) strObj;
//        System.out.println("读取到的内容为：");
//        System.out.println("----------------------------------------分隔符---------------------------------------------");
//        System.out.println(str);
//        System.out.println("------------------------------------------------------------------------------------------");
        String replace = str.replace("\n", "<br/>\n");
        System.out.println("处理后的内容为：");
        System.out.println("----------------------------------------分隔符---------------------------------------------");
        System.out.println(replace);
        System.out.println("------------------------------------------------------------------------------------------");
    }
}
